﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;

namespace AMSReportBuildService
{
    class AssetValueDistributeByAreaXmlFile
    {
        GetDataSetHelp m_Help = new GetDataSetHelp();
        internal void CreateXmlFile(string path)
        {
            var ds = m_Help.AssetValueDistributeByAreaData;
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                //初始化XML文档操作类
                var myXml = new XmlDocument();

                //建立Xml的定义声明
                XmlDeclaration dec = myXml.CreateXmlDeclaration("1.0", "GB2312", null);
                myXml.AppendChild(dec);

                XmlElement rootNode = myXml.CreateElement("chart");
                rootNode.SetAttribute("caption", "资产价值分布报表");
                rootNode.SetAttribute("xAxisName", "区域");
                rootNode.SetAttribute("yAxisName", "金额");
                rootNode.SetAttribute("showValues", "1");
                rootNode.SetAttribute("numberPrefix", "$");
                rootNode.SetAttribute("decimals", "0");
                rootNode.SetAttribute("formatNumberScale", "0");
                rootNode.SetAttribute("baseFontSize", "12");
                myXml.AppendChild(rootNode);
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    XmlElement ele0 = myXml.CreateElement("set");
                    ele0.SetAttribute("label", row["Name"].ToString());
                    ele0.SetAttribute("value", row["value"].ToString());
                    string toolText = row["value"] + "，" + (Convert.ToDouble(row["value"].ToString()) / GetDataSetHelp.GetAssetTotalValue()).ToString("0.00%");
                    ele0.SetAttribute("tooltext", toolText);
                    if (myXml.DocumentElement != null) myXml.DocumentElement.AppendChild(ele0);
                }
                if (File.Exists(path))
                  File.Delete(path);
                myXml.Save(path);
            }
        }

 
    }
}
